import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		appId: 'wx2959a675e140ffec',
		openExamine: false,//是否开启审核状态
		token: '',
		authLocation: -1, // 是否开启定位
		code: null,
		isLoginStatus: false, // 是否登录
		userInfo: {},
		timerIdent: false,//全局1s定时器，只在全局开启一个，所有需要定时执行的任务监听该值即可，无需额外开启
		// 默认城市
		addressInfo:{
			city: '',
			district: '',
			street: '',
			province: '',
			address: '',
			name: '',
			city_code: '',
			lat: '',
			lng: '',
		},
		dicTypeList: [],
		config: {
		    // poster: '', // 生成海报的气泡文字
		    // messageTips: '', //留言列表顶部的提示文字
		    // explain: '', //联系客服的文字说明
		    // weixinhao: '', // 联系客服的文字微信号
		    // miniProgramName: '', //关联的小程序名称
		    // miniProgramLink: '', //关联的小程序链接
		    // payPrice: '',
		    // iosPayFlag: '',
		    // andriodPayFlag: '',
		    // payBtnText: '',
		    // releaseFlag: false
			SW_INTEGRAL_TOPUP: 0,
			SW_SHOW_POSTER: 0,
			PARAM_WECHAT: ''
		},
	},
	getters: {
		hasLogin(state){
			return !!state.isLoginStatus;
		},
		hasLocationStatus(state) {
			return !!state.locationStatus
		}
	},
	mutations: {
		//更新state数据
		setStateAttr(state, param){
			if(param instanceof Array){
				for(let item of param){
					state[item.key] = item.val;
				}
			}else{
				state[param.key] = param.val;
			}
		},
		setLocation(state, data) {
			state.authLocation = data
			uni.setStorageSync('authLocation', data)
		},
		setUserInfo(state, data) {
			state.userInfo = data
			state.isLoginStatus = true
		},
		clearUserInfo(state) {
			state.userInfo = {}
			state.isLoginStatus = false
		},
		//更新token
		setToken(state, data){
			const {token, tokenExpired} = data;
			state.token = token;
			uni.setStorageSync('uniIdToken', token);
			uni.setStorageSync('tokenExpired', tokenExpired);
		},
		//退出登录
		logout(state){
			state.token = '';
			uni.removeStorageSync('uniIdToken');
			setTimeout(()=>{
				state.userInfo = {};
			}, 1100)
		},
		newCityFun(state, newCity) {
			state.addressInfo.city = newCity.city
			state.addressInfo.district = newCity.district
			state.addressInfo.street = newCity.street
			state.addressInfo.province = newCity.province
			state.addressInfo.address = newCity.address
			state.addressInfo.name = newCity.name
			state.addressInfo.city_code = newCity.city_code
			state.addressInfo.lat = newCity.lat
			state.addressInfo.lng = newCity.lng
		},
		setCode(state, code) {
			state.code = code
		},
		setDicTypeList(state, data) {
			state.dicTypeList = data
		},
		setConfig(state, list) {
		    state.config = {
		        // poster: list[0].paramValue,
		        // messageTips: list[1].paramValue,
		        // explain: list[2].paramValue,
		        // weixinhao: list[3].paramValue,
		        // miniProgramName: list[4].paramValue,
		        // miniProgramLink: list[5].paramValue,
		        // payPrice: list[8].paramValue,
		        // iosPayFlag: list[6].paramValue,
		        // andriodPayFlag: list[7].paramValue,
		        // payBtnText: list[9].paramValue,
		        // releaseFlag: list[11].paramValue,
				SW_INTEGRAL_TOPUP: list[21].paramValue,
				SW_SHOW_POSTER: list[22].paramValue,
				PARAM_WECHAT: list[23].paramValue
		    };
		    console.log(state);
		},
	},
	actions: {
	}
}) 


export default store